//************************************************************
//	COPYRIGHT 2011 Birthin' Hips - ALL RIGHTS RESERVED
//************************************************************
//
//	$Id: PositionUpdate.java$
//
//	$Date: 12/13/11$
//
//	Reason: Message that holds 4 integers: and X position, Y position, Z position, and time offset
//
//*************************************************************

/** $Author: Colton Presler, Ross Kahn, Elysia Haight$ */
/** $Revision: $ */

package com; 

import java.util.Arrays;

//==============================================================
public class PositionUpdate implements Message {

	// Indices in the position array for the different data
	public static final int TIME_INDEX = 0;	
	public static final int X_INDEX = 1;
	public static final int Y_INDEX = 2;
	public static final int Z_INDEX = 3;
	
	private int[] posArray;  	// Integer array of data. Data will be placed according to the indices above
	
	/**
	 * Constructor. Takes information on the position information, and places it in the position array according to the position indices
	 * @param timeOffset	Position data
	 * @param X				Position data
	 * @param Y				Position data
	 * @param Z				Position data
	 */
	//----------------------------------------------------------
	public PositionUpdate(int timeOffset, int X, int Y, int Z){
		posArray = new int[4];
		posArray[TIME_INDEX] = timeOffset;
		posArray[X_INDEX] = X;
		posArray[Y_INDEX] = Y;
		posArray[Z_INDEX] = Z;
	}
	
	/**
	 * Returns data at a specified position index
	 * @param posIndex	position index to retreive data from
	 * @return			position data at given index
	 */
	//----------------------------------------------------------
	public int getPosInfo(int posIndex){
		return posArray[posIndex];
	}
	
	
	/**
	 * Returns entire array of position data
	 * @return		all position data as an int array
	 */
	//----------------------------------------------------------
	public int[] getPosInfo(){
		return posArray;
	}
	
	/**
	 * Returns true if a given object is equal to this PositionUpdate message. Uses built-in
	 * Java functionality to determine if the int arrays of the two objects (assuming the object
	 * is a PositionUpdate instance; if not, return false) are equal.
	 */
	//----------------------------------------------------------
	public boolean equals(Object o){
		if(o instanceof PositionUpdate){
			PositionUpdate toCompare = (PositionUpdate) o;
			if(Arrays.equals(toCompare.getPosInfo(), posArray)){
				return true;
			}else{
				return false;
			}
		}else{
			return false;
		}
	}
	
	/**
	 * Converts this message into a String for logging
	 */
	//----------------------------------------------------------
	public String toString(){
		return "Time: " + posArray[TIME_INDEX] +
			   "; X Position: " + posArray[X_INDEX] +
			   "; Y Position: " + posArray[Y_INDEX] +
			   "; Z Position: " + posArray[Z_INDEX];
	}	
}
